import Vue from 'vue'
import Router from 'vue-router'
import Test from './modules/Test'
import approval from './modules/approval'
import attendance from './modules/attendance'
import department from './modules/department'
import employee from './modules/employee'
import permission from './modules/permission'
import role from './modules/role'
import salary from './modules/salary'
import social from './modules/social'
import newPage from './modules/newPage'

Vue.use(Router)

// 导出动态添加的路由
export const asyncPermRoutes = [
  Test,
  department,
  role,
  employee,
  permission,
  attendance,
  approval,
  salary,
  social,
  newPage
]

export const constantRoutes = [
  { path: '/login', component: () => import('@/views/login') },
  { path: '/', component: () => import('@/layout'), redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard'),
        name: 'dashboard',
        // meta 对象是控制 侧边栏Sidebar组件显示的
        meta: {
          title: '首页', // 显示的文字
          icon: 'dashboard' // 现在的svg图标
        },
        hidden: false // 控制是否要在侧边显示
      }
      // 一个路由里面 有多个孩子会出现嵌套下拉列表 所以要保证children里面只能有一个
    ]
  },

  { path: '/404', component: () => import('@/views/404'), hidden: true }
  // 404 page must be placed at the end !!!

]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()
router.addRoutes(asyncPermRoutes)

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
